package com.cheng.im.service.conversation.controller;

import com.cheng.im.service.common.model.SyncReq;
import com.cheng.im.service.common.model.SyncResp;
import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.conversation.domain.ImConversationSet;
import com.cheng.im.service.conversation.model.req.AddConversationSetReq;
import com.cheng.im.service.conversation.model.req.DeleteConversationReq;
import com.cheng.im.service.conversation.model.req.PullConversationSet;
import com.cheng.im.service.conversation.model.req.UpdateConversationReq;
import com.cheng.im.service.conversation.model.resp.PullConversationSetResp;
import com.cheng.im.service.conversation.service.ImConversationSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "聊天会话")
@RestController
@RequestMapping("v1/conversation")
public class ImConversationSetController {

    @Resource
    ImConversationSetService imConversationSetService;

    /**
     * 删除会话
     * @param req
     * @return
     */
    @ApiOperation(value = "删除会话", notes = "IM删除用户的聊天会话")
    @DeleteMapping("/deleteConversation")
    public CommonResult deleteConversation(@RequestBody @Validated DeleteConversationReq req)  {
        return imConversationSetService.deleteConversation(req);
    }

    @ApiOperation(value = "更新会话", notes = "IM更新用户的聊天会话")
    @PutMapping("/updateConversation")
    public CommonResult updateConversation(@RequestBody @Validated UpdateConversationReq req)  {
        return imConversationSetService.updateConversation(req);
    }

    @ApiOperation(value = "同步会话", notes = "IM同步用户的聊天会话列表")
    @PostMapping("/syncConversationList")
    public CommonResult<SyncResp<ImConversationSet>> syncFriendShipList(@RequestBody @Validated SyncReq req)  {
        return imConversationSetService.syncConversationSet(req);
    }

    /**
     * 为了应付毕设写的接口
     * @param req
     * @return
     */
    @ApiOperation(value = "拉取会话", notes = "IM拉取用户的最近聊天会话列表，适用于WebSocket端的使用，直接拉取最近会话")
    @PostMapping("/pullConversationList")
    public CommonResult<List<PullConversationSetResp>> pullConversationList(@RequestBody @Validated PullConversationSet req)  {
        return imConversationSetService.pullConversationSet(req);
    }

    @ApiOperation(value = "增加会话", notes = "IM新增用户的聊天会话")
    @PostMapping("/addConversationSet")
    public CommonResult addConversationSet(@RequestBody @Validated AddConversationSetReq req)  {
        return imConversationSetService.addConversationSet(req);
    }
}
